
int packFloat(double value)
{
	int object = allocate(4);
	*(int*)object = Float | 1; //1=2wordheader
	object+=4;
	*(int*)object = (6 << 8) | (3 << 2) | 1;
	*(double*)(object+4) = value;
	return object;
}

double unpackFloat(int oop)
{
	if( classOf(oop)==Float ) return *(double*)(oop+4); 
	success=0;
	return 0.0;
}

/* <primitive: 40>
 * <Number> asFloat
 * Answer the floating-point representation of the receiver. Fail if the receiver is not a Number.
 * Essential.
 */
void primAsFloat()
{
	int rcv = unpackSmInt(peek(0));
	if(success) popNandPush(1, packFloat((double)rcv));

	//No need to handle LargeIntegers?  Seems code for this exists in the image.
}

/* <primitive: 41>
 * <Float> + <Float>
 * Add the receiver to the argument. Fail if the receiver or argument is not a Float.
 * Essential.
 */
void primFloatAdd()
{
	double rcv = unpackFloat(peek(1));
	double arg = unpackFloat(peek(0));
	
	if(success) popNandPush(2, packFloat(rcv+arg));
}

/* <primitive: 42>
 * <Float> - <Float>
 * Subtract the argument from the receiver. Fail if the receiver or argument is not a Float.
 * Essential.
 */
void primFloatSubtract()
{
	double rcv = unpackFloat(peek(1));
	double arg = unpackFloat(peek(0));
	
	if(success) popNandPush(2, packFloat(rcv-arg));
}

/* <primitive: 43>
 * <Float> < <Float>
 * Answer if the reciever is less than the argument. Fail if the receiver or argument is not a Float.
 * Essential.
 */
void primFloatLessThan()
{
	double rcv = unpackFloat(peek(1));
	double arg = unpackFloat(peek(0));
	
	if(success) popNandPush(2, rcv<arg ? true : false );
}

/* <primitive: 44>
 * <Float> > <Float>
 * Answer if the reciever is greater than the argument. Fail if the receiver or argument is not a Float.
 * Essential.
 */
void primFloatGreaterThan()
{
	double rcv = unpackFloat(peek(1));
	double arg = unpackFloat(peek(0));
	
	if(success) popNandPush(2, rcv>arg ? true : false );
}

/* <primitive: 45>
 * <Float> <= <Float>
 * Answer if the reciever is less than or equal to the argument. Fail if the receiver or argument is not a Float.
 * Essential.
 */
void primFloatLessOrEqual()
{
	double rcv = unpackFloat(peek(1));
	double arg = unpackFloat(peek(0));
	
	if(success) popNandPush(2, rcv<=arg ? true : false );
}

/* <primitive: 46>
 * <Float> >= <Float>
 * Answer if the reciever is greater than or equal to the argument. Fail if the receiver or argument is not a Float.
 * Essential.
 */
void primFloatGreaterOrEqual()
{
	double rcv = unpackFloat(peek(1));
	double arg = unpackFloat(peek(0));
	
	if(success) popNandPush(2, rcv>=arg ? true : false );
}

/* <primitive: 47>
 * <Float> = <Float>
 * Answer if the reciever is equal to the argument. Fail if the receiver or argument is not a Float.
 * Essential.
 */
void primFloatEqual()
{
	double rcv = unpackFloat(peek(1));
	double arg = unpackFloat(peek(0));
	
	if(success) popNandPush(2, rcv==arg ? true : false );
}

/* <primitive: 48>
 * <Float> ~= <Float>
 * Answer if the reciever is not equal to the argument. Fail if the receiver or argument is not a Float.
 * Essential.
 */
void primFloatNotEqual()
{
	double rcv = unpackFloat(peek(1));
	double arg = unpackFloat(peek(0));
	
	if(success) popNandPush(2, rcv!=arg ? true : false );
}

/* <primitive: 49>
 * <Float> * <Float>
 * Answer the reciever multiplied by the argument. Fail if the receiver or argument is not a Float.
 * Essential.
 */
void primFloatMultiply()
{
	double rcv = unpackFloat(peek(1));
	double arg = unpackFloat(peek(0));
	
	if(success) popNandPush(2, packFloat(rcv*arg));
}

/* <primitive: 50>
 * <Float> / <Float>
 * Answer the reciever divided by the argument. Fail if the receiver or argument is not a Float, or if the argument represents zero.
 * Essential.
 */
void primFloatDivide()
{
	double rcv = unpackFloat(peek(1));
	double arg = unpackFloat(peek(0));
	
	if(success) {
		if(arg == 0.0) 
			success=0; //divide by zero
		else
			popNandPush(2, packFloat(rcv/arg));
	}
}

/* <primitive: 51>
 * <Float> truncated
 * Answer the reciever without its fraction part. Fail if the receiver is not a Float, or if the answer cannot be represented as a SmallIntger.
 * Essential.
 */
void primTruncated()
{
	double rcv = unpackFloat(peek(0));
	int ans = packSmInt( (int)rcv );
	
	if(success) popNandPush(1, ans);
}

/* <primitive: 52>
 * <Float> fractionPart
 * Answer a Float for (self - self asInteger). 
 * Optional.
 */
void primFractionPart()
{
	success = 0;
}

/* <primitive: 53>
 * <Float> exponent
 * Consider the receiver to be represented as a power of two multiplied by a mantissa (between one and two). Answer with the SmallInteger to whose power two is raised.
 * Optional.
 */
void primExponent()
{
	success = 0;
}  

/* <primitive: 54>
 * <Float> exponent
 * Answer with the receiver multiplied by 2.0 raised to the power of the argument.
 * Optional.
 */
void primTimesTwoPower()
{
	success = 0;
}  

/* <primitive: 55>
 * <Float> sqrt
 * Answer the square root of the receiver.
 * Optional.
 */
void primSqrt()
{
	success = 0;
}   

/* <primitive: 56>
 * <Float> sin
 * Answer the sine of the receiver interpreted in radians.
 * Optional.
 */
void primSin()
{
	success = 0;
}   

/* <primitive: 57>
 * <Float> exponent
 * Answer the inverse tangent of the receiver as an angle in radian.
 * Optional.
 */
void primAtan()
{
	success = 0;
}    

/* <primitive: 58>
 * <Float> ln
 * Answer with the natural (base-e) logarithmn of the reciever.
 * Optional.
 */
void primLn()
{
	success = 0;
}

/* <primitive: 59>
 * <Float> exponent
 * Answer e rasied to the power of the receiver.
 * Optional.
 */
void primExp()
{
	success = 0;
}    
